const path = require('path')
const HtmlWebpackPlugin = require('html-webpack-plugin');
const webpack = require('webpack')
const isDev = process.env.NODE_ENV === 'development'
const config = {
    mode:"development",
    entry:path.join(__dirname,"./src/index.ts"),
    output:{
        path:path.join(__dirname,'/dist'),
        filename:'[name].bundle.js'
    },
    plugins:[
        new HtmlWebpackPlugin({
            template: path.join(__dirname, './src/index.html')
        })
    ],
    resolve: {
        extensions: ['.js', '.ts','.tsx','jsx'],
      },
    module: {
        rules:[
            {
                test: /\.ts$/,
                use: 'ts-loader',
                exclude: [
                    path.resolve(__dirname, './node_modules')
                  ]
            },
            {
                test: /\.js$/,
                loader: 'babel-loader',
                exclude: [
                  path.join(__dirname, './node_modules')
                ]
              }
        ]
    },
}
if (isDev) {
    config.devServer = {
        host: '0.0.0.0',
        port: 3002,
        contentBase: path.join(__dirname, 'dist'), 
        compress: true, 
        historyApiFallback: true, 
        overlay:{
            errors:true,
            warnings:false
        }
  }
  config.plugins.push(new webpack.HotModuleReplacementPlugin())
}
module.exports = config